Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestions #7382

Merged
merged 2 commits into from
Jan 7, 2025
Merged

suggestions #7382

merged 2 commits into from
Jan 7, 2025

Conversation

matthieusieben
Copy link
Contributor

No description provided.

@@ -16,9 +16,9 @@ export * as profile from '#/types/atproto/profile'
* }
* ```
*/
export function fastIsType<R>(
export function fastIsType<R extends {$type?: string}>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change prevents using fastIsType with a type param R that does not match the predicate function.

Comment on lines 261 to 265
// Type casting here is actually safe because here we check for the
// actual type bellow
const record = notif.record as
| AppBskyFeedRepost.Record
| AppBskyFeedLike.Record
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally! This is actually what fastIsType is doing as well, just casting the values without validation. I decided to make the util so that it's clear what's happening when that util is used, instead of feeling the need to leave a comment on each type cast as you did here. That seem reasonable to you?

Comment on lines +19 to +21
export function fastIsType<R extends {$type?: string}>(
record: unknown,
identity: <V>(v: V) => boolean,
identity: <V>(v: V) => v is V & {$type: NonNullable<R['$type']>},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh v nice!

Copy link

github-actions bot commented Jan 7, 2025

Old size New size Diff
6.86 MB 6.86 MB -75 B (-0.00%)

Comment on lines 26 to 31
embed?:
| $Typed<AppBskyEmbedRecordWithMedia.View>
| $Typed<AppBskyEmbedImages.View>
| $Typed<AppBskyEmbedVideo.View>
| $Typed<AppBskyEmbedExternal.View>
| {$type: string}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get why this makes sense and is probably the most academic way of doing this, but a few things I don't like:

  • We lose the relationship between the prop embed and the origin of the data in PostView['embed']. The way it was typed before makes it very obvious how this component is used
  • Having to remember to duplicate the forwards compat via {$type: string} in components like this is boilerplate I don't think we want. If we adopt this pattern, we'll be doing this in hundreds of places.
  • Having to reconstruct these types exactly but understanding exactly what can be passed in here (plus needing the $Type util) requires understanding of the data on both sides of this component. This makes it more cumbersome to make "dumb" components that can be composed and reused throughout the app.

@estrattonbailey estrattonbailey merged commit e4ee457 into next/base Jan 7, 2025
6 of 7 checks passed
estrattonbailey added a commit that referenced this pull request Jan 8, 2025
* suggestions

* Revert unneeded changes

---------

Co-authored-by: Eric Bailey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants